<?php namespace system\model;
use houdunwang\model\Model;
class Tag extends Model{
	//数据表
	protected $table = "tag";

    /**
     * 添加标签
     * @return bool
     */
    public function store(){
        //检测是否为空
        $handel=str_replace("|",'',$_POST['tname']);
//        p(strlen($handel));die;
        if(strlen($_POST['tname'])==0){
            return false;
        }
        //标签分割
        $tags=explode('|',$_POST['tname']);
        foreach ($tags as $k=>$v){
            if(strlen($v)!=0){
                $this->insertGetId(['tname'=>$v]);
            }
        }
        //返回操作结果
        return true;
    }

    /**
     * 修改标签
     */
     public function editTag($tid){
        $tname=$_POST['tname'];
        if(strlen($tname)=='0'){
            return false;
        }
        $this->where('tid',$tid)->update(['tname'=>$tname]);
        return true;
     }
}